#include <avr/wdt.h>												//Watchdog timer library
#include <avr/io.h>
#include <avr/interrupt.h>

void WDT_Init(void)
{
	//cli();
	wdt_reset();															//reset watchdog
	WDTCSR |= (1<<WDCE)|(1<<WDE); 
	WDTCSR = (1<<WDE)|(1<<WDP2)|(1<<WDP1)|(1<<WDP0);				//No interrupt before reset + Start watchdog timer with 2s prescaler
	//sei();
}

void reset_wdt()
{
		wdt_reset();		//Reset watchdog timer
}

void WDT_off(void)
{
	//cli();
	wdt_reset();
	/* Clear WDRF in MCUSR */
	MCUSR &= ~(1<<WDRF);
	/* Write logical one to WDCE and WDE */
	/* Keep old prescaler setting to prevent unintentional time-out */
	WDTCSR |= (1<<WDCE) | (1<<WDE);
	/* Turn off WDT */
	WDTCSR = 0x00;
	//sei();
}

//Watchdog timeout ISR
// ISR(WDT_vect)
// {
// 	
// }
